package cn.itcast.user.service;

import cn.itcast.user.mapper.UserMapper;
import cn.itcast.user.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.atomic.AtomicInteger;

@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;
    private AtomicInteger atomicInteger = new AtomicInteger(0);

    public User queryById(Long id) {
        atomicInteger.getAndAdd(1);
        System.out.println(atomicInteger.get());
        if (atomicInteger.get()>50){
            throw new RuntimeException("我出问题了哈");
        }
        if (atomicInteger.get()<30) {
            try {
                Thread.sleep(atomicInteger.get() * 10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return userMapper.findById(id);
    }
}